<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head th:replace="layout :: common_header(~{::title})">
    <title>订单管理-OMS订单管理系统</title>

</head>
<body th:replace="layout :: common_body(~{::div.layui-body})">
<div class="layui-body" style="padding:15px;">
    <div class="layui-tab layui-tab-brief" lay-filter="demo">
        <ul class="layui-tab-title">
            <li class="layui-this">订单管理</li>
        </ul>
    </div>
    <style>
        .hideAddress{
            width: 300px;
            display: inline-block;
            overflow: hidden;
            text-overflow: ellipsis;
        }
    </style>
    <!-- content starts -->
    <!--    <blockquote class="layui-elem-quote">订单总览</blockquote>-->

    <fieldset class="layui-elem-field">
        <legend>按条件搜索</legend>
        <div class="layui-field-box">
            <form class="layui-form layui-form-pane1" method="get" th:action="@{/order/list}">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="orderNum" id="orderNum" th:value="${orderNum}" placeholder="订单编号" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <input type="text" name="contactMobile" id="contactMobile" th:value="${contactMobile}" placeholder="收货人手机号" class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">下单时间</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="startTime" th:value="${startTime}" id="startTime" autocomplete="off"
                                   placeholder="yyyy-MM-dd">
                        </div>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" name="endTime" th:value="${endTime}" id="endTime" autocomplete="off"
                                   placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="salesManId" id="salesManId">
                                <option value="0">业务员</option>
                                <option th:each="item:${salesMan}" th:value="${item.id}" th:text="${item.trueName}">样品</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <div class="layui-input-inline">
                            <select name="status" id="status">
                                <option value="">状态</option>
                                <option th:each="item: ${T(com.huayi.order.enums.EnumErpOrderStatus).values()}" th:text="${item.name}" th:value="${item.index}">等待发货</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn">搜索</button>
                        <i>总共：<span style="color: red" th:text="${totalSize}"></span>条记录</i>
                    </div>

                    <div class="layui-inline">
                        <input type="button" class="layui-btn layui-btn layui-btn-primary" id="excel_btn" value="导出当前结果"/>
                    </div>

                </div>

            </form>
        </div>
    </fieldset>

    <!-- start dd-wrapper -->
    <link rel="stylesheet" href="/css/order_list.css"/>
    <div class="dd-wrapper">
        <table class="dd-table">
            <tr>
                <th>ID</th>
                <th>订单编号</th>
                <th >商品</th>
                <th>订单金额</th>
<!--                <th >下单日期</th>-->
                <th >下单时间</th>
                <th >支付状态</th>
                <th >收货人</th>
                <th >备注</th>
                <th>物流信息</th>
                <th>订单状态</th>
                <th>操作</th>
            </tr>
            <tr th:each="item:${lists}">
                <td th:text="${item.id}"></td>
                <td th:text="${item.orderNum}"></td>
                <td>
                    <div th:each="it:${item.items}">
<!--                        <img th:src="${it.goodsImage}" width="50px" height="50px">-->
                        <p>
                            <span th:text="${#strings.abbreviate(it.goodsTitle,18)}"></span><br/>
                            [[${it.skuInfo}]]<br/>
                            单价: ¥<span th:text="${it.price}"></span> 数量：<span th:text="${it.quantity}"></span>
                        </p>
                    </div>
                </td>
                <td><b>¥<span th:text="${item.totalAmount}"></span></b><br>（含运费：¥<span th:text="${item.shippingFee}"></span>）</td>
<!--                <td th:text="${item.orderDate}"></td>-->
                <td>
                    <p th:text="${ #dates.format(item.createOn * 1000, 'yyyy-MM-dd HH:mm:ss')}"></p>
                </td>
                <td>
                    <p th:text="${T(com.huayi.order.enums.EnumSalesOrderPayStatus).getName(item.payStatus)}"></p>
                </td>
                <td>
                    <div>
                        <p ><span th:text="${item.contactPerson}"></span>&nbsp;<span th:text="${item.contactMobile}"></span></p>
                        <p ><span th:text="${item.address}"></span></p>
                    </div>
                </td>
                <td th:text="${item.sellerMemo}"></td>
                <td>

                        <span th:if="${item.logisticsStatus ==0 && item.logisticsType == 0}" style="color: red">未打单</span>
                        <div th:if="${item.logisticsStatus ==1 &&item.logisticsType == 0}">
                            <span th:text="${item.logisticsCompany}"></span>&nbsp;<br />
                            <span th:text="${item.logisticsCode}"></span>&nbsp;
                        </div>


                    <p th:if="${item.logisticsType == 1}">
                        <span style="color: red" th:if="${item.logisticsType ==1 }">用户自提</span>
                    </p>

                </td>
                <td>
                    <span  th:text="${T(com.huayi.order.enums.EnumErpOrderStatus).getName(item.status)}"></span>
                </td>
                <td>
                    <a th:href="@{/order/detail(id=${item.getId()})}">查看详情</a><br />
                    <a  th:if="${item.status == T(com.huayi.order.enums.EnumErpOrderStatus).CANCEL.index || item.status == T(com.huayi.order.enums.EnumErpOrderStatus).WaitAudit.index}" th:href="@{/order/edit(id=${item.getId()})}">修改订单</a><br />
                    <a class="track print_express" th:if="${item.status != T(com.huayi.order.enums.EnumErpOrderStatus).CANCEL.index && item.status != T(com.huayi.order.enums.EnumErpOrderStatus).WaitAudit.index}" th:attr="order-id=${item.getId()}" href="javascript:;">打印快递面单</a><br />

<!--                    <a th:if="${item.logisticsStatus == 1 && item.status == T(com.huayi.order.enums.EnumErpOrderStatus).WaitSend.index }" th:attr="order-id=${item.getId()}" class="order_send" >订单发货</a>-->
                    <p style="padding-top: 10px;" th:if="${item.status == T(com.huayi.order.enums.EnumErpOrderStatus).WaitSend.index }" >
                        <input th:attr="order-id=${item.getId()}" type="button" class="layui-btn layui-btn-sm layui-btn-normal order_send_confirm" value="订单发货"/>
                        <input th:attr="order-id=${item.getId()}" type="button" class="layui-btn layui-btn-sm layui-btn-primary order_cancel" value="取消订单"/>
                    </p>
                    <p style="padding-top: 10px;" th:if="${item.status == T(com.huayi.order.enums.EnumErpOrderStatus).Delivered.index }" >
                        <input th:attr="order-id=${item.getId()}" type="button" class="layui-btn layui-btn-sm layui-btn-primary order_refund" value="退货"/>
                    </p>
                </td>
            </tr>
        </table>
    </div>
    <!-- end dd-wrapper -->
    <div class="layui-box layui-laypage layui-laypage-default pageBox">
        <paging:pager th:value="${pageIndex}" th:rows="${totalSize}" th:size="${pageSize}"/>
    </div>

    <!--<script src="/jquery-3.3.1.min.js"></script>-->
    <script type="text/javascript" src="/Tips.js"></script>
    <script type="text/template" id="send-template">
        <div class="T-box">
            <p><span>快递公司</span>
                <select id="send-express">
                    <option value="1">韵达快递</option>
                    <option value="2" selected>百世快递</option>
                </select>
            </p>
        </div>
    </script>
    <script type="text/javascript">
        var layer;
        var $;
        var windowOpen;

        //计算天数差的函数，通用
        function DateDiff(sDate1, sDate2) { //sDate1和sDate2是2019-3-12格式
            var aDate, oDate1, oDate2, iDays
            aDate = sDate1.split("-")
            oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]) //转换为9-25-2017格式
            aDate = sDate2.split("-")
            oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0])
            iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24) //把相差的毫秒数转换为天数
            return iDays
        }

        layui.use(['laydate', 'jquery', 'form', 'layer'], function () {
            var laydate = layui.laydate;
            $ = layui.jquery;
            var form = layui.form;
            layer = layui.layer;
            laydate.render({
                elem: '#startTime'
            });
            laydate.render({
                elem: '#endTime'
            });
            //下拉框默认值
            var status = '[[${status}]]';
            if (status != '')
                $("#status").val(status);

            var salesManId = '[[${salesManId}]]';
            if(salesManId!='')
                $("#salesManId").val(salesManId);

            form.render();
            $(function () {
                //打印快递单弹窗
                $(".print_express").click(function (e) {
                    e.stopPropagation();
                    e.preventDefault();
                    var id = $(this).attr("order-id");
                    Tips.confirm({
                        title: '打印订单快递单',
                        content: $('#send-template').html(),
                        define: function () {
                            layer.open({
                                type: 2,
                                title: '打印订单快递单',
                                shadeClose: true,
                                shade: 0.8,
                                area: ['940px', '90%'],
                                content: '/order/order_send_express?id=' + id+'&express='+ $("#send-express  option:selected").val()//iframe的url
                            });
                        }
                    });
                })
                $(".order_send_confirm").click(function () {
                    var orderId = $(this).attr("order-id");
                    layer.open({
                        type: 2,
                        title: '订单发货',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['940px', '90%'],
                        content: '/order/order_send?id=' + orderId //iframe的url
                    });
                })
                $(".order_refund").click(function () {
                    if (confirm("确定要退货吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order/order_refund",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("退货成功！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }
                });
                $(".order_cancel").click(function () {
                    if (confirm("确定要取消订单吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order/order_cancel",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("订单已取消！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }

                })

                $(".order_send").click(function () {
                    if (confirm("确定要发货吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order/order_send",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("发货成功！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }
                })

                //导出当前结果
                $("#excel_btn").click(function () {
                    //组合条件
                    var url = "/order/order_list_excel_export?excel=1";
                    var orderNum = $("input[name=orderNum]").val();
                    var mobile = $("input[name=contactMobile]").val();
                    var status = $("#status").val();
                    var startTime = $("input[name=startTime]").val();
                    var endTime = $("input[name=endTime]").val();

                    if (orderNum != '') {
                        url += "&orderNum=" + orderNum;
                    }
                    if (mobile != '') {
                        url += "&contactMobile=" + mobile;
                    }
                    if (status != '') {
                        url += "&status=" + status;
                    }
                    if (startTime != '') {
                        url += "&startTime=" + startTime;
                    }
                    if (endTime != '') {
                        url += "&endTime=" + endTime;
                    }

                    if (confirm("当前有[[${totalSize}]]条数据，确认要导出吗？")) {
                        window.open(url, "_blank");
                        //?billNo=&contractNo=&startTime=2019-12-13&endTime=2019-12-13
                    }
                })


                //取消订单
                $(".cancel_order").click(function () {
                    if (confirm("确定要取消订单吗？")) {
                        var orderId = $(this).attr("order-id");
                        $.ajax({
                            url: "/ajax_order_confirm/order_cancel",
                            type: "POST",
                            dataType: "JSON",
                            contentType: 'application/json',
                            data: JSON.stringify({orderId: orderId}),
                            success: function (res) {
                                if (res.code == 0) {
                                    alert("取消成功！");
                                    window.location.reload();
                                } else {
                                    alert(res.msg);
                                }


                            }
                        })
                    }
                })
            })//$(function(){})
        });

    </script>


</div>
</body>
</html>
